<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich" 
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:composition>
        <style type="text/css">
            .center{
                text-align:center;
                font-family:黑体;
                font-weight:bold;
                font-size: 50px;
            }
            .gridStyle input[type='text']{
                width:200px;
            }
            .selectStyle{
                width: 200px;
            }
            .itemClass{
                width:50%;
            }
            .pic{
                margin-bottom: -4px;
                margin-right: -2px;
                border:none;
                width:20px;
                height:20px;
            }
            .col1{
                width:60px;                
            }
            .col{
                width:200px;
            }
            .col3{
                width:80px;
            }
        </style>
        <script type="text/javascript">
            javascript:window.history.forward(1);
        </script>
        <h:body>
            <h:form id="loanbill">
                <rich:panel styleClass="content-hight">
                    <rich:messages globalOnly="true"/>
                    <h:panelGrid columns="4">
                        <h:outputLabel value="单据状态:"/>
                        <h:panelGroup>
                            <h:outputText value="已提交等待审核"  rendered="#{loan.exp.numberStatus eq '0'}" style="color:green"/>
                            <h:outputText value="未提交" rendered="#{loan.exp.numberStatus eq '1'}" style="color:red"/>
                            <h:outputText value="审核通过等待支付"  rendered="#{loan.exp.numberStatus eq '2'}" style="color:blue"/>
                            <h:outputText value="退回修改"  rendered="#{loan.exp.numberStatus eq '3'}" style="color:red"/>
                            <h:outputText value="确认支付"  rendered="#{loan.exp.numberStatus eq '4'}" style="color:blue"/>
                            <h:outputText value="撤单"  rendered="#{loan.exp.numberStatus eq '5'}" style="color:red"/>
                            <h:outputText value="支付完毕"  rendered="#{loan.exp.numberStatus eq '6'}" style="color:blue"/>
                        </h:panelGroup>
                        <h:outputLabel value="审核信息：" rendered="#{not empty loan.exp.checkInfo}" style="margin-left: 50px;"/>
                        <h:outputText value="#{loan.exp.checkInfo}"/>
                    </h:panelGrid>
                    <rich:toolbar  itemSeparator="grida">
                        <rich:toolbarGroup>
                            <h:commandLink  action="#{loan.add}" disabled="#{!loan.showAble}"
                                            style=" margin: 1px;">
                                <h:graphicImage value="./images/create_doc.gif" styleClass="pic" title="新增" />                            
                            </h:commandLink>

                            <h:commandLink  action="#{loan.checkandRep}" disabled="#{loan.saveOrNot}"
                                            actionListener="#{loan.clearQueryResult}" style=" margin: 1px;">
                                <h:graphicImage value="./images/save.gif" styleClass="pic" title="保存" />
                            </h:commandLink>

                            <h:commandLink action="#{loan.update}" style=" margin: 1px;"
                                           immediate="true"
                                           disabled="#{loan.addOrUpdate || loan.exp.number eq '' || (loan.exp.numberStatus != '1' and loan.exp.numberStatus != '3')}">
                                <h:graphicImage value="./images/edit.gif" styleClass="pic" title="修改" />
                            </h:commandLink>

                            <h:commandLink  action="#{loan.delete}"
                                            actionListener="#{loan.clearQueryResult}"
                                            style=" margin: 1px;"
                                            disabled="#{loan.addOrUpdate || loan.exp.number eq '' || (loan.exp.numberStatus != '1' and loan.exp.numberStatus != '3')}">
                                <h:graphicImage value="./images/delete.gif" styleClass="pic" title="删除" />
                            </h:commandLink>


                            <h:commandLink action="#{loan.cancel}" disabled="#{loan.saveOrNot}"
                                           immediate="true"
                                           style=" margin: 1px;text-decoration: none;">
                                <h:panelGroup style="white-space: nowrap;">
                                    <h:graphicImage value="./images/cancel.png" styleClass="pic" />
                                    <h:outputLabel value="取消" />
                                </h:panelGroup>
                            </h:commandLink>


                            <h:commandLink  action="#{loan.submitBill}" actionListener="#{loan.clearQueryResult}"
                                            style=" margin: 1px;text-decoration: none;"
                                            disabled="#{loan.addOrUpdate || loan.exp.number eq '' || !loan.saveOrNot || loan.exp.numberStatus != '1'}">
                                <h:panelGroup style="white-space: nowrap;">
                                    <h:graphicImage value="./images/submit.png" styleClass="pic"  />
                                    <h:outputLabel value="提交" />
                                </h:panelGroup>
                            </h:commandLink>

                            <h:commandLink action="#{loan.rescind}" actionListener="#{loan.clearQueryResult}"
                                           style=" margin: 1px;text-decoration: none;"
                                           disabled="#{!loan.browAble || loan.exp.numberStatus != '0'}">
                                <h:panelGroup style="white-space: nowrap;">
                                    <h:graphicImage value="./images/repeat.png" styleClass="pic"  />
                                    <h:outputLabel value="撤单" />
                                </h:panelGroup>
                            </h:commandLink>


                            <h:commandLink  action="#{loan.getFirst}" style=" margin: 1px;"
                                            disabled="#{!loan.showAble}">
                                <h:graphicImage value="./images/btn_page_first.gif" styleClass="pic" title="首张" />
                            </h:commandLink>

                            <h:commandLink  action="#{loan.previouse}" style=" margin: 1px;"
                                            disabled="#{!loan.showAble}">
                                <h:graphicImage value="./images/btn_page_up.gif" styleClass="pic" title="上张" />
                            </h:commandLink>

                            <h:commandLink action="#{loan.next}" style=" margin: 1px;"
                                           disabled="#{!loan.showAble}">
                                <h:graphicImage value="./images/btn_page_down.gif" styleClass="pic" title="下张" />
                            </h:commandLink>

                            <h:commandLink  action="#{loan.getLast}" style=" margin: 1px;"
                                            disabled="#{!loan.showAble}">
                                <h:graphicImage value="./images/btn_page_end.gif" styleClass="pic" title="末张" />
                            </h:commandLink>

                            <a4j:commandLink render="loanPdf" execute="@this"
                                             oncomplete="#{rich:component('voucherPanel')}.show();"
                                             style=" margin: 1px;"
                                             disabled="#{!loan.showAble or empty loan.exp.number}">
                                <h:graphicImage value="./images/print.gif" styleClass="pic" title="打印" />
                            </a4j:commandLink>

                        </rich:toolbarGroup>
                    </rich:toolbar>

                    <p style="text-align:center;font-family:黑体;font-weight:bold;font-size: 20px !important;" >借 款 单</p>
                    <hr style="border:1px dashed;"/>
                    <h:panelGroup id="edit">
                        <h:panelGrid columns="6" width="100%"  border="0" id="loanbillinput"
                                     style="text-align:left;"
                                     styleClass="gridStyle"
                                     columnClasses="col1,col,clo2,col3,col,clo2" >
                            <h:outputLabel value="单据编号:" />
                            <h:inputText  id="number"  disabled="true" value="#{loan.exp.number}"
                                          required="true" requiredMessage="不能为空"/>
                            <rich:message for="number"/>

                            <h:outputLabel value="单据日期:" />
                            <h:panelGroup id="billDate">
                                <rich:calendar disabled="#{loan.showAble}"
                                               value="#{loan.exp.numDate}"
                                               locale="zh_CN"
                                               popup="true"
                                               datePattern="yyyy-MM-dd"
                                               showApplyButton="false"
                                               inputClass="inputstype"
                                               required="true" requiredMessage="不能为空"/>
                            </h:panelGroup>
                            <rich:message for="billDate"/>

                            <h:outputLabel value="预算项目:"/>
                            <h:inputText  id="projName" disabled="#{loan.showAble}" value="#{loan.exp.project.finName}"
                                          onclick="#{rich:component('projPanel')}.show();"/>
                            <rich:message for="projName"/>

                            <h:outputLabel value="借款部门:" />                       
                            <h:inputText  id="paydept"  disabled="#{loan.showAble}"
                                          value="#{loan.exp.payDept.name}"
                                          onclick="#{rich:component('deptPanel')}.show();"/>
                            <rich:message for="paydept"/>

                            <h:outputLabel value="借款人:"/>
                            <rich:select id="feePerson"
                                         value="#{loan.exp.feePer.cpsn_number}"      
                                         enableManualInput="true" immediate="true"
                                         disabled="#{loan.showAble}"
                                         required="#{!loan.showAble}" requiredMessage="不能为空">
                                <f:selectItem itemValue="" itemLabel="-请选择-"/>
                                <f:selectItems value="#{loan.perli}" />
                            </rich:select>
                            <rich:message for="feePerson"/>

                            <h:outputLabel value="借款事由:"  />
                            <h:inputText  id="affair" disabled="#{loan.showAble}" value="#{loan.exp.affair}" 
                                          required="true" requiredMessage="不能为空"
                                          validatorMessage="请勿超过30个字">
                                <f:validateLength maximum="30"/>
                            </h:inputText>
                            <rich:message for="affair"/>

                            <h:outputLabel value="备注:"  />
                            <h:inputText  id="memo" disabled="#{loan.showAble}" value="#{loan.exp.memo}"
                                          validatorMessage="请勿超过50个字">
                                <f:validateLength maximum="50"/>
                            </h:inputText>
                            <rich:message for="memo"/>

                            <h:outputLabel value="借款金额:"  />
                            <h:inputText  id="total" disabled="#{loan.showAble}" value="#{loan.exp.total}"
                                          required="true" requiredMessage="不能为空"
                                          converterMessage="请输入正确的数字。">
                                <a4j:ajax  immediate="false" event="keyup"/>
                                <f:convertNumber type="double" pattern="###,##0.00"/>
                            </h:inputText>
                            <rich:message for="total" style="color:red"/>

                            <h:outputText value="支付方式:"/>
                            <rich:select value="#{loan.exp.payStyle.code}"
                                         styleClass="selectStyle"
                                         id="payway"
                                         valueChangeListener="#{loan.payStyleChange}"
                                         disabled="#{loan.showAble}"
                                         required="#{!loan.showAble}" requiredMessage="不能为空">
                                <f:selectItem itemValue="" itemLabel="-请选择-"/>
                                <f:selectItems value="#{loan.payStyleli}" />
                            </rich:select>
                            <rich:message for="payway"/>

                            <h:outputLabel value="是否限额:"  />
                            <h:selectOneRadio id="quota" value="#{loan.exp.isQuota}" disabled="#{loan.showAble}" 
                                              required="true" requiredMessage="不能为空">
                                <f:selectItem itemLabel="限额" itemValue="限额"/>
                                <f:selectItem itemLabel="非限额" itemValue="非限额"/>
                            </h:selectOneRadio>
                            <rich:message for="quota" style="color:red"/>   

                            <h:outputLabel value="附件张数:"/>
                            <h:inputText id="affix" value="#{loan.exp.affixAmount}" disabled="#{loan.showAble}"/>
                            <rich:message for="affix"/>
                        </h:panelGrid>
                        <hr style="border:1px dashed;"/>
                        <h:panelGrid columns="6" width="100%"  border="0"
                                     style="text-align:left;"
                                     styleClass="gridStyle"
                                     columnClasses="col1,col,clo2,col3,col,clo2" >
                            <h:outputLabel value="部门名称:" />
                            <h:outputText  id="department"   value="#{loan.exp.dept.name}"  />
                            <rich:message for="department"/>

                            <h:outputLabel value="制 单 人: "/>
                            <h:outputText  id="person"  value="#{loan.exp.user.cpsn_name}"  />
                            <rich:message for="person"/>
                        </h:panelGrid>
                    </h:panelGroup>
                </rich:panel>
            </h:form>
        </h:body>

        <rich:popupPanel header="打印" id="voucherPanel" width="950" height="600">
            <f:facet name="controls">
                <h:outputLink value="#" onclick="#{rich:component('voucherPanel')}.hide();">关闭</h:outputLink>
            </f:facet>
            <a4j:mediaOutput element="object" cacheable="false" id="loanPdf"
                             uriAttribute="data"
                             standby="Loading Pdf..." mimeType="application/pdf"
                             type="application/pdf" style="width: 900px;height: 550px"
                             createContent="#{loan.process}">
            </a4j:mediaOutput>
        </rich:popupPanel>

        <rich:popupPanel id="deptPanel" autosized="true">
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="费用承担部门"></h:outputText>
                </h:panelGroup>
            </f:facet>
            <f:facet name="controls">
                <h:outputLink value="#" onclick="#{rich:component('deptPanel')}.hide();">关闭</h:outputLink>
            </f:facet>
            <h:form>
                <rich:panel>
                    <h:panelGrid columns="2"  border="0" id="mainform">
                        <rich:tree value="#{departmentBean.rootNode}" var="idept"
                                   selectionType="ajax" toggleType="client"
                                   selectionChangeListener="#{loan.selected}"
                                   style="width:300px" render="paydept,feePerson">
                            <rich:treeNode>
                                <h:outputText value="[#{idept.data.code}]#{idept.data.name}" />
                                <rich:componentControl target="deptPanel" operation="hide" event="click"/>
                            </rich:treeNode>
                        </rich:tree>
                    </h:panelGrid>
                </rich:panel>
            </h:form>

            <f:facet name="footer">
                footer!
            </f:facet>

        </rich:popupPanel>

        <rich:popupPanel id="projPanel" autosized="true">
            <f:facet name="header">项目信息</f:facet>
            <f:facet name="controls">
                <h:outputLink value="#" onclick="#{rich:component('projPanel')}.hide();">关闭</h:outputLink>
            </f:facet>
            <h:form id="projList">
                <rich:dataTable id="editTable" value="#{loan.finProjModel}" rows="10"  var="pro">
                    <rich:column>
                        <f:facet name="header">
                            <h:panelGroup>
                                <h:outputText value="预算项目编码"/>
                            </h:panelGroup>
                        </f:facet>
                        <a4j:commandLink id="Projlinks" action="#{loan.projSelected}"
                                         onclick="#{rich:component('projPanel')}.hide();"
                                         render="projName" >
                            <h:outputText value="#{pro.finCode}"/>
                        </a4j:commandLink>
                    </rich:column>

                    <rich:column>
                        <f:facet name="header">
                            <h:panelGroup>
                                <h:outputText value="预算项目名称"/>
                            </h:panelGroup>
                        </f:facet>
                        <h:outputText value="#{pro.finName}"/>
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">
                            <h:panelGroup>
                                <h:outputText value="备注"/>
                            </h:panelGroup>
                        </f:facet>
                        <h:outputText value="#{pro.memo}"/>
                    </rich:column>
                    <f:facet name="footer">
                        <rich:dataScroller id="ds"></rich:dataScroller>
                    </f:facet>
                </rich:dataTable>
            </h:form>
        </rich:popupPanel>
    </ui:composition>
</html>
